package com.gtw.modules.api.controller;

import java.util.List;
import java.util.Map;

import com.gtw.common.annotation.AuthIgnoreApi;
import com.gtw.common.utils.PageUtils;
import com.gtw.common.utils.Query;
import com.gtw.common.utils.R;
import com.gtw.modules.api.service.TbSearchInfoService;
import com.gtw.modules.entity.TbBanner;
import com.gtw.modules.entity.TbSearchHot;
import com.gtw.modules.entity.TbSearchInfo;
import com.gtw.modules.sys.service.SysTbSearchHotService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户搜索记录
 *
 * @author wuye
 * @email www.baidu.com
 * @date 2018-02-06 15:19:47
 */
@RestController
@RequestMapping("/api/searchinfo")
public class TbSearchInfoController {
    @Autowired
    private TbSearchInfoService searchInfoService;

    @Autowired
    private SysTbSearchHotService sysTbSearchHotService;

    /**
     * 列表
     */
    @AuthIgnoreApi
    @RequestMapping("/list")
    public R list(String uid) {
        //查询列表数据
        List<TbSearchInfo> searchInfoList = searchInfoService.findByKes(uid);

        return R.ok().put("data", searchInfoList);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id) {
        TbSearchInfo searchInfo = searchInfoService.queryObject(id);

        return R.ok().put("searchInfo", searchInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TbSearchInfo searchInfo) {
        searchInfoService.save(searchInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TbSearchInfo searchInfo) {
        searchInfoService.update(searchInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids) {
        searchInfoService.deleteBatch(ids);

        return R.ok();
    }


    /**
     * 查询所有搜索热门名词
     * @return
     */
    @AuthIgnoreApi
    @RequestMapping("/foundSearchHot")
    public R foundSearchHot(){
        List<TbSearchHot> list = sysTbSearchHotService.queryAll();
        return R.ok().put("data",list);
    }

}
